package com.haoan.index.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.haoan.common.annotation.Anonymous;
import com.haoan.index.domain.CulturalRelic;
import com.haoan.index.domain.Place;
import com.haoan.index.service.PlaceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haoan.common.annotation.Log;
import com.haoan.common.core.controller.BaseController;
import com.haoan.common.core.domain.AjaxResult;
import com.haoan.common.enums.BusinessType;
import com.haoan.index.domain.Ticket;
import com.haoan.index.service.TicketService;
import com.haoan.common.utils.poi.ExcelUtil;
import com.haoan.common.core.page.TableDataInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 门票Controller
 *
 * @author autoGen
 * @date 2025-01-03
 */
@Api(value="门票",tags = "门票")
@RestController
@RequestMapping("/index/ticket")
public class TicketController extends BaseController
{
    @Resource
    private TicketService ticketService;
    @Resource
    private PlaceService placeService;

    /**
     * 点赞
     */
    @ApiOperation("点赞")
    @Anonymous
    @GetMapping(value = "thumbsUp/{id}")
    public AjaxResult thumbsUp(@PathVariable("id") Long id)
    {
        Ticket ticket = ticketService.selectTicketById(id);

        ticket.setLikes(ticket.getLikes()+1L);
        ticketService.updateTicket(ticket);
        return success(ticket);
    }

    /**
     * 查询门票列表
     */
    @ApiOperation("查询门票列表")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(Ticket ticket)
    {
        startPage();
        List<Ticket> list = ticketService.selectTicketList(ticket);
        return getDataTable(list);
    }

    /**
     * 导出门票列表
     */
    @ApiOperation("导出门票列表")
    @PreAuthorize("@ss.hasPermi('index:ticket:export')")
    @Log(title = "门票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Ticket ticket)
    {
        List<Ticket> list = ticketService.selectTicketList(ticket);
        ExcelUtil<Ticket> util = new ExcelUtil<Ticket>(Ticket.class);
        util.exportExcel(response, list, "门票数据");
    }

    /**
     * 获取门票详细信息
     */
    @ApiOperation("获取门票详细信息")
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        Ticket ticket = ticketService.selectTicketById(id);
        Place place = placeService.selectPlaceById(ticket.getPlaceId());
        ticket.setPlaceName(place.getName());
        ticket.setRegion(place.getRegion());
        return success(ticket);
    }

    /**
     * 新增门票
     */
    @ApiOperation("新增门票")
    @PreAuthorize("@ss.hasPermi('index:ticket:add')")
    @Log(title = "门票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Ticket ticket)
    {
        return toAjax(ticketService.insertTicket(ticket));
    }

    /**
     * 修改门票
     */
    @ApiOperation("修改门票")
    @PreAuthorize("@ss.hasPermi('index:ticket:edit')")
    @Log(title = "门票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Ticket ticket)
    {
        return toAjax(ticketService.updateTicket(ticket));
    }

    /**
     * 删除门票
     */
    @ApiOperation("删除门票")
    @PreAuthorize("@ss.hasPermi('index:ticket:remove')")
    @Log(title = "门票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ticketService.deleteTicketByIds(ids));
    }
}
